/**
 * 
 */
package com.neal.domain.securities;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

import com.neal.domain.enums.UserStatus;

/**
 * 
 * @author Neal
 * @version 1.0
 * @description 用户类
 */
@Entity
@Table(name = "SYS_USER")
public class User implements Serializable {

	private static final long serialVersionUID = -8010116751675956418L;

	/** 用户登入账号 **/
	@Id
	@Column(name = "USER_ID", length = 36)
	private String userId;

	/** 姓名 **/
	@Column(name = "USER_NAME", length = 10)
	private String userName;

	/** 密码 **/
	@Column(name = "PASSWORD", length = 32)
	private String password;

	/** 用戶描述 **/
	@Column(name = "USER_NOTE")
	private String note;

	/** 用戶狀態  0:enable 1:disable**/
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "USER_STATUS", nullable = false)
	private UserStatus status = UserStatus.ENABLE;

	/** 角色 **/
	@ManyToOne
	@JoinColumn(name = "ROLE_ID")
	private Role role;

	@Column(name="USER_CREATE_DATE")
	@DateTimeFormat(pattern="yyyy/MM/dd")
	private Date createDate = new Date();

	/**
	 * 构造初始化UUID
	 */
	public User() {
		this.userId = UUID.randomUUID().toString();
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public UserStatus getStatus() {
		return status;
	}

	public void setStatus(UserStatus status) {
		this.status = status;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((userId == null) ? 0 : userId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (userId == null) {
			if (other.userId != null)
				return false;
		} else if (!userId.equals(other.userId))
			return false;
		return true;
	}

}
